

var app=getApp();
Page({
  data:{
    userid:'',
    show:false,        //前期白屏
    isCreated:3,      //是否创建
    avatar:'',
    name:'',
    company:'',
    position:'',
    mobile:'',
    email:'',          
    remark:'',        
    isMarked:0,         //是否收藏了这个人
    isme:false,       //是否是自己
    showmodal:false   //显示弹出层
  },
  onLoad:function(options){
    var tmp=this;
    tmp.setData({
      userid:options.userid
    });
  },
  onReady:function(){
    app.loading();
    var tmp=this;
    //
    app.login(function(res){
       wx.setStorageSync('sss', res.data.sss);

       console.log(app.s3());

       app.uploadinfo(res.data.sss,function(res){
         
          tmp.setData({
            isCreated:res.data.isCreated
          });
          tmp.getinfo(tmp.data.userid);
       });
    });
    //


  },
  onShow:function(){
    // 页面显示
  },
  onHide:function(){
    // 页面隐藏
  },
  onUnload:function(){
    // 页面关闭
  },
  //share
   onShareAppMessage: function () {
     var tmp=this;
     tmp.isMarked=0;
     tmp.isme=0;
    return {
      title: tmp.data.name+'的名片',
      path: 'pages/card/card?userid='+tmp.data.userid
    }
  },

  //获取用户信息
  //无userid 自己 有 别人
  getinfo:function(userid){
    var tmp=this;
       wx.request({
         url: app.host+app.path+'info',
         data: {
           userid:userid,
           sss:app.s3()
         },
         method: 'POST',
         success: function(res){
           tmp.setData({
             name:res.data.name,
             userid:res.data.userid,
             avatar:res.data.avatar,
             cardbg:res.data.cardbg,
             company:res.data.company,
             position:res.data.position,
             email:res.data.email,
             mobile:res.data.mobile,
             more:res.data.more,
             isme:res.data.isme,
             isMarked:res.data.isMarked
           });
           tmp.setData({
             show:true
           });
           app.hidetoast();
         },
         fail: function() {
           app.alert('网络连接失败');
         },
         complete: function() {
           // complete
         }
       })
    
  },
  //去编辑图片
  editcard:function(){
    app.to('../../pages/editcard/editcard');
  },
  //名片夹
  cards:function(){
    app.to('../../pages/cards/cards');
  },
  //我的名片
  mycard:function(){
    app.to('../../pages/card/card');
  },
  //显示收藏弹出层
  showmodal:function(){
    var tmp=this;
    tmp.setData({
      showmodal:true
    });
  },
  //页面关闭
  cancel:function(){
    var tmp=this;
    tmp.setData({
      showmodal:false
    });
  },
  //收藏
 
  mark:function(e){
    var tmp=this;
    wx.request({
      url: app.host+app.path+'mark',
      data: {
        userid:tmp.data.userid,
        formid:e.detail.formId,
        remark:e.detail.value.remark,
        sss:app.s3()
     },
      method: 'POST', 
      success: function(res){
        if (res.data.Status==1)
        {
            app.toast('收藏成功');
            tmp.setData({
              showmodal:false
            });
            setTimeout(function(){
              app.hidetoast();
            },1000);
            tmp.setData({
              isMarked:1
            });
        }
      },
      fail: function() {
        app.alert('网络连接失败');
      },
      complete: function() {
        // complete
      }
    });
    
  },
  //反收藏
  unmark:function(){
    var tmp=this;
    wx.request({
      url: app.host+app.path+'unmark',
      data: {
        userid:tmp.data.userid,
        sss:app.s3()
     },
      method: 'POST', 
      success: function(res){
        if (res.data.Status==1)
        {
            app.toast('取消收藏');
            setTimeout(function(){
              app.hidetoast();
            },1000);
            tmp.setData({
              isMarked:0
            });
        }
      },
      fail: function() {
        app.alert('网络连接失败');
      },
      complete: function() {
        // complete
      }
    });
  },
  //递名片
  sendcard:function(){
    var tmp=this;
    app.alert('请点击右上角→分享')
  }
})